package com.gxz.service.impl;

import com.gxz.common.Result;
import com.gxz.exception.BussinessException;
import com.gxz.exception.SystemException;
import com.gxz.mapper.AccountMapper;
import com.gxz.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    AccountMapper accountMapper;

    @Override
    public void transfer() {
        accountMapper.inMoney("钱大富", 50D);
        // 测试事务
        double i = 1/0;
        accountMapper.outMoney("老段", 50D);
    }

    @Override
    public Result testException(Integer  id) {
        if(id ==  5) {
            throw new BussinessException(Result.BUSINESS_ERR_CODE, "用户不存在");
        }
        if(id == 6) {
            throw new SystemException(Result.SYSTEM_ERR_CODE, "系统异常，请稍后重试！");
        }
        if(id == 7) {
            throw new RuntimeException("未知异常");
        }
        return null;
    }
}
